package com.imufe.chemicalenterprisedangerwarning.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imufe.chemicalenterprisedangerwarning.entity.query.CreateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.query.SafetySupervisionBureauQuery;
import com.imufe.chemicalenterprisedangerwarning.entity.query.UpdateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.SafetySupervisionBureauDetailedVO;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.SafetySupervisionBureauVO;
import com.imufe.chemicalenterprisedangerwarning.service.SafetySupervisionBureauService;
import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 安监局 前端控制器
 * <p>
 *
 * @author BaiBan
 * @since 2022-09-23
 */

@Api(tags = "安监局")
@RestController
@RequestMapping("/safety-supervision-bureau")
public class SafetySupervisionBureauController {

    @Autowired
    SafetySupervisionBureauService service;

    @ApiOperation(value = "安监局列表", notes = "安监局的列表(分页)")
    @GetMapping("/page")
    public ResponseEntity<IPage<SafetySupervisionBureauVO>> page(@RequestParam(value = "current", defaultValue = "1") Long current) {
        IPage<SafetySupervisionBureauVO> page = service.page(current);
        return ResponseEntity.success(page);
    }

    @ApiOperation(value = "安监局详情", notes = "安监局的详细信息")
    @GetMapping("/detailed")
    public ResponseEntity<SafetySupervisionBureauDetailedVO> detailed(Long id) {
        SafetySupervisionBureauDetailedVO detailed = service.detailed(id);
        return ResponseEntity.success(detailed);
    }

    @ApiOperation(value = "查找安监局", notes = "查找此区域最近的上级安监局信息")
    @GetMapping("/get/by/region")
    public ResponseEntity<SafetySupervisionBureauVO> getByRegion(Long id) {
        SafetySupervisionBureauVO vo = service.getByRegion(id);
        return ResponseEntity.success(vo);
    }

    @ApiOperation(value = "新增", notes = "新增一个安监局，返回新增的安监局信息")
    @PostMapping("/create")
    public ResponseEntity<SafetySupervisionBureauDetailedVO> create(@RequestBody @Validated(CreateGroup.class) SafetySupervisionBureauQuery query) {
        SafetySupervisionBureauDetailedVO detailedVO = service.create(query);
        return ResponseEntity.success(detailedVO);
    }

    @ApiOperation(value = "删除", notes = "删除一个安监局")
    @DeleteMapping("/delete")
    public ResponseEntity<?> delete(@RequestBody Long id) {
        service.removeById(id);
        return ResponseEntity.success();
    }

    @ApiOperation(value = "修改", notes = "修改一个安监局，返回修改后的安监局信息")
    @PutMapping("/update")
    public ResponseEntity<SafetySupervisionBureauDetailedVO> update(@RequestBody @Validated(UpdateGroup.class) SafetySupervisionBureauQuery query) {
        SafetySupervisionBureauDetailedVO detailedVO = service.update(query);
        return ResponseEntity.success(detailedVO);
    }
}